const spawn = require('cross-spawn');
const czConventionalChangelog = require('cz-conventional-changelog');

module.exports = {
	prompter: function(cz, commit) {
		const isNoVerify = process.argv.includes('--no-verify');

		if (isNoVerify) {
			console.log('Skipping lint check due to --no-verify flag');
			return czConventionalChangelog.prompter(cz, commit);
		}

		console.log('Running lint check before commit...');
		const lintResult = spawn.sync('npm', ['run', 'lint'], { stdio: 'inherit' });
    
		if (lintResult.status !== 0) {
			console.error('Lint check failed. Please fix the errors before committing.');
			console.log('You can bypass this check by using "git cz --no-verify"');
			process.exit(1);
		}

		console.log('Lint check passed. Proceeding with commit...');
		czConventionalChangelog.prompter(cz, commit);
	}
};